
<template>
	<view class="discount page bgf5">
	
		<view class="flex flexC   c00 fs16 px10 py6 bgff px15">
			<text class="pt8 pb4  flex1 aliC" :class="index==currentTab?'active':''" v-for="(item,index) in tabs" :key="index" @click="switchTab(index)">{{item}}</text>
		</view>

		<!-- 团购券 -->
		<group-coupon ref="groupCoupon" v-if="currentTab == 0" :statusBar="statusBar"></group-coupon>
		<!-- 优惠券 -->
		<coupon-box ref="couponBox" v-else-if="currentTab == 1"></coupon-box>
	
	</view>
</template>

<script>
	const statusBar = uni.getSystemInfoSync().statusBarHeight + 10;
	export default {
		data() {
			return {
				statusBar,
				tabs: [ '团购券', '优惠券'],
				currentTab: 0,
				list: [],
				selectShop:null,
				keyword:"",
				isSearch:false,
				id:''
			};
		},
		
		onLoad(option) {
			
			
			this.id = option.id;
			
			this.getDetail();
		
			
		},
		
		onShow() {
			
			
		},
		methods: {
			
			search(e){
				
				this.keyword = e;
				this.getShopList();
				this.isSearch = true;
				console.info("=====search====="+e);
			},
			
			getDetail() {
				let param = {
					id: this.id
				};
				let that = this;
				this.$api.getShopDetail(param).then(res => {
			
					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.selectShop = res.data;
						that.onSelectShop(res.data);
					} else {
			
					}
				})
			},
			
			// 选择店铺
			onSelectShop(item) {
				this.selectShop = item;
				
				 if(this.currentTab == 0) {
					this.$refs.groupCoupon.getData(this.selectShop);
				}else if(this.currentTab == 1) {
					this.$refs.couponBox.getData(this.selectShop);
				}
			},
			getShopList(){
				let param = {
					keyword:this.keyword,
					orgId:uni.getStorageSync("orgId",53)
				};
				let that = this;
				this.$api.shopList(param).then(res => {
					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.list = res.data;
						console.info("=====dddddddd==="+that.id);
						if(that.id == ""){
							that.selectShop = that.list[0];
							that.switchTab(that.currentTab)
							//that.$refs.accountRecharge.getCharge(that.selectShop);
						}else{
							that.getDetail();
						}
					
					} else {
				
					}
				})
			},
			switchTab(index){
				this.currentTab = index;
				this.$nextTick(() => {
					if(this.currentTab == 0) {
						this.$refs.groupCoupon.getData(this.selectShop);
					}else if(this.currentTab == 1) {
						this.$refs.couponBox.getData(this.selectShop);
						
					}
				})
			},
			
			openShopPicker() {
				this.$refs.shopPicker.open();
			},
			onClose() {
				this.$refs.shopPicker.close();
			}
		}
	}
</script>

<style lang="scss">
.discount {
	.icon {width: 38rpx;}
	.down {width: 20rpx;height: 20rpx;}
	.ellipsis1 {max-width: 200rpx;}
	.active {
		position: relative;
		&::after {
			content: '';
			width: 120rpx;
			height: 8rpx;
			background-color: #F8B62B;
			border-radius: 8rpx;
			position: absolute;
			bottom: 0;
			left: calc(50% - 60rpx);
		}
	}
}
</style>
